package com.apes.fn.scm.merchant.disbursement.repository;

import com.apes.fn.fico.debitnote.model.BusinessDebitNote;
import com.apes.fn.scm.merchant.disbursement.model.DisbursementItem;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author cyy
 */
public interface DisbursementItemRepository extends CustomRepository<DisbursementItem, String> {

    @Query("select T from DisbursementItem T where T.merchantAccountSettlement.id = :settlementId AND T.merchantBankAccount.id = :merchantBankId AND T.disbursement.state != 'approve' AND T.disbursement.state != 'delete'")
    DisbursementItem findHistory(@Param("settlementId")String settlementId, @Param("merchantBankId")String merchantBankId);

    @Query("select T from DisbursementItem T where T.businessDebitNote.id = :businessDebitNoteId AND T.disbursement.state != 'approve' AND T.disbursement.state != 'delete'")
    DisbursementItem findByBusinessDebitNote(@Param("businessDebitNoteId")String businessDebitNoteId);
}
